﻿using System;
using System.Collections.Generic;
using System.Data;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectSunny.Admin.Controls
{
    public partial class EditVideo : System.Web.UI.UserControl
    {
        public string name;
        public string date;
        public string link;
        public string active;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //Them du lieu vao cat 1              
                DataTable dt = DAL.DCollector.DBCollector.Instance.CallSQL1Param( "SELECT * FROM tbl_Video", true);
                name = dt.Rows[0]["Video_Name"].ToString();
                link = dt.Rows[0]["Video_Link"].ToString();
                active = dt.Rows[0]["Video_Active"].ToString();
                txtName.Text = name;
                txtDate.Text = DateTime.Now.ToString();
                txtLink.Text = link;

            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            if (txtName.Text != "")
            {
                if (txtLink.Text != "")
                {
                    string name = txtName.Text;
                    string link = txtLink.Text;
                    DAL.DHelpers.Column[] cl = new DAL.DHelpers.Column[2];
                    cl[0] = new DAL.DHelpers.Column("Video_Name", name, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                    cl[1] = new DAL.DHelpers.Column("Video_Link", link, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);

                    string colWhere ="Video_ID";

                    string  colValue =  "1";

                    DAL.DCollector.DBCollector.Instance.StoredUpdate("tbl_Video", cl, colWhere, colValue);

                    Response.Redirect("/Admin/Index.aspx?panel=7&sub=9");
                }
                else
                {
                    Response.Write("<script>alert('Vui lòng nhập tên video...')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('Vui lòng nhập link video...')</script>");
            }
        }
    }
}